package com.newcoin.chat.beans;

import com.newcoin.chat.beans.entity.FriendMsgEntity;
import com.newcoin.chat.beans.entity.GroupMsgEntity;
import com.newcoin.chat.beans.vo.FriendOfflineMsgVo;
import com.newcoin.chat.beans.vo.GroupOfflineMsgVo;

import java.util.Comparator;

public class ComparatorTime implements Comparator {
    @Override
    public int compare(Object o1, Object o2) {
        FriendOfflineMsgVo fMsg;
        GroupOfflineMsgVo gMsg;
        FriendOfflineMsgVo fMsg1;
        GroupOfflineMsgVo gMsg1;
        if (o1 instanceof FriendMsgEntity) {
            fMsg = (FriendOfflineMsgVo) o1;
            if (o2 instanceof GroupMsgEntity) {
                gMsg = (GroupOfflineMsgVo) o2;
                return fMsg.getLastMessageTime().compareTo(gMsg.getLastMessageTime());
            } else {
                fMsg1 = (FriendOfflineMsgVo) o2;
                return fMsg.getLastMessageTime().compareTo(fMsg1.getLastMessageTime());
            }
        } else {
            gMsg = (GroupOfflineMsgVo) o1;
            if (o2 instanceof FriendMsgEntity) {
                fMsg = (FriendOfflineMsgVo) o2;
                return gMsg.getLastMessageTime().compareTo(fMsg.getLastMessageTime());
            } else {
                gMsg1 = (GroupOfflineMsgVo) o2;
                return gMsg.getLastMessageTime().compareTo(gMsg1.getLastMessageTime());
            }
        }
    }
}
